using UnityEngine;
using UnityEngine.EventSystems;

public class SelectableButton : MonoBehaviour
{
	public SelectableButtonController selectableButtonController;

	[HideInInspector]
	public bool selected;

	[HideInInspector]
	public new bool enabled = true;

	public string id = string.Empty;

	[SerializeField]
	protected GameObject selectedBG;

	[SerializeField]
	protected GameObject notSelectedBG;

	[SerializeField]
	protected GameObject disabledBG;

	public EventTrigger.TriggerEvent customCallback;

	public virtual void OnClick()
	{
		if (enabled)
		{
			Select(true);
			if ((bool)GameUI.instance)
			{
				GameUI.instance.currSelectableButton = this;
			}
		}
	}

	public virtual void Enable()
	{
		enabled = true;
		if (selectedBG != null)
		{
			selectedBG.SetActive(false);
		}
		if (notSelectedBG != null)
		{
			notSelectedBG.SetActive(true);
		}
		if (disabledBG != null)
		{
			disabledBG.SetActive(false);
		}
	}

	public virtual void Disable()
	{
		enabled = false;
		if (selectedBG != null)
		{
			selectedBG.SetActive(false);
		}
		if (notSelectedBG != null)
		{
			notSelectedBG.SetActive(false);
		}
		if (disabledBG != null)
		{
			disabledBG.SetActive(true);
		}
	}

	public virtual void Select(bool select)
	{
		if (selectedBG != null)
		{
			selectedBG.SetActive(select);
		}
		if (notSelectedBG != null)
		{
			notSelectedBG.SetActive(!select);
		}
		if (selected != select)
		{
			selected = select;
			if (select)
			{
				InvokeCustomCallback();
			}
			if (selectableButtonController != null)
			{
				selectableButtonController.SelectButton(this);
			}
		}
	}

	public void InvokeCustomCallback()
	{
		if (customCallback != null)
		{
			customCallback.Invoke(null);
		}
	}
}
